<?php


namespace App\Logic;

use App\Utils\Singleton;
use App\Exceptions\ApiException;
use App\Models\ExamModel;
use App\Models\QuestionModel;
use App\Models\ExaminfoModel;
use Illuminate\Http\Request;
use Illuminate\Http\Response;


class ExaminfoLogic
{
    use Singleton;

    /**
     * @param $examinfo_id
     * @return
     */

    public function get(Request $request)
    {
        // $result_question_id = ExamModel::getInstance()->getOne(["question_id"], ['exam_id' => $exam_id]); //查找question_id
        // $result_subject_id = QuestionModel::getInstance()->getOne(["subject_id"],
        //     ['question_id' => $result_question_id->question_id]);//查找subject_id
        // $result_examInfo_id = ExaminfoModel::getInstance()->getOne(["examInfo_id"],
        //     ['subject_id' => $result_subject_id->subject_id]);//查找是否有该科考试信息
        // if ($result_examInfo_id) {
        //     date_default_timezone_set('PRC');
        //     $start = date("Y-m-d H:i:s", time());
        //     $end = date("Y-m-d H:i:s", strtotime("+1 hours"));
        //     $long_time = floor((strtotime($end) - strtotime($start)) % 86400 / 60);
        // }
        // $insertInfo = ['start' => $start, 'end' => $end, 'long_time' => $long_time]; //要插入的考生开始考试的时间
        // ExaminfoModel::getInstance()->insertData($insertInfo);  //将考试信息插入
        // $arr = [$long_time, $start, $end];
        // return $arr;

        $subject_id = $request->input('subject_id');
        $subject_id = decrypt($subject_id);

        $result = ExaminfoModel::getInstance()->getOne(["long_time", "start", "end","subject_name"], ['subject_id' => $subject_id]);
        $result = objectToArray($result);

        $data = array();

        $data['long_time'] = $result['long_time'];
        $data['start'] = $result['start'];
        $data['end'] = $result['end'];
        $data['subject_name'] = $result['subject_name'];

        return $data;


        // foreach ($result as $k => $v) {
        //     //var_dump($k);
        //     if ($k == 'long_time') {
        //
        //         //var_dump($v);
        //     }
        //     if ($k == 'start') {
        //         $v = $result->start;
        //         //var_dump($v);
        //     }
        //     if ($k == 'end') {
        //         $v = $result->end;
        //         //var_dump($v);
        //     }
        // }
        //  var_dump($re);
        // return [];
    }
}


